import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import {createHtmlPlugin} from 'vite-plugin-html'
import {resolve} from "path";

const moduleName = process.env['npm_config_project'] // 使用`--project=[module_name]`获取模块名
console.log(moduleName,999)
let config;
if(!moduleName){
  config = {
    plugins: [vue()],
    resolve: {
      alias: {
        // 为`vite.config.ts`文件所在目录起别名`@`
        '@': resolve(__dirname, './'),
      }
    },
  }
}else{
  config = {
    plugins: [vue()],
    root: `./src/${moduleName}`,
    resolve: {
      alias: {
        '@': resolve(__dirname, './'),
      }
    },
    build: {
      // https://cn.vitejs.dev/guide/build.html
      rollupOptions: {
        input: resolve(__dirname, `./src/${moduleName}/index.html`), // 指定子模块入口文件
        output: {
          dir: `dist/${moduleName}`
        }
      }
    }
  }
}

// https://vitejs.dev/config/
export default defineConfig(config)
